/*
 * Copyright 2009 (c) Patrick Pietens.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package indigo.control
{
	import indigo.errors.IndigoError;
	import indigo.model.ApplicationModel;
	import indigo.views.ViewLocator;

	/**
	 * Often <code>Commands</code> are called worker classes because they are responsible for actually carrying out the work 
	 * behind your application. Each and every command exposes a single entry point, a method called execute(), which allows 
	 * any <code>Object</code> to invoke the <code>Command</code> without understanding what the command accomplishes.</p>
	 * 
	 * <p>Within an MVC framework there is a Controller which controls all your worker classes. It responds to user gestures 
	 * by executing linked <code>Commands</code>. The Indigo Framework does not implement this Controller. Instead it executes 
	 * <code>Commands</code> directly from your <code>Views</code>.</p> 
	 * 
	 * <p>Use the Indigo Templates for FDT to quickly build a new <code>Command</code>.</p>
	 * 
	 * @example
	 * <code>
	 * <listing>
	 * <pre>
	 * </pre>
	 * </listing>
	 * </code> 
	 * 
	 * @playerversion Flash 9
	 * @langversion ActionScript 3.0
	 * @see executeCommand
	 */
	public class Command
	{
		/**
		 * The entry point of your Command. Executes the Command.
		 * @param Object that holds data used by the Command
		 * 
		 */
		public function execute( event:IndigoNotice ):void
		{
			throw new Error( IndigoError.METHOD_EXCEPTION );
		}


		public function sendNotification( type:String, data:* = null ):void
		{
			var myEvent:IndigoNotice = new IndigoNotice( type );
			myEvent.data = data;

			NotificationCenter.getInstance().dispatchEvent( myEvent );
		}


		public function listenToNotification( event:String, listener:Function ):void
		{
			NotificationCenter.getInstance().addEventListener( event, listener, false, 1, true );
		}


		public function get applicationModel():ApplicationModel
		{
			return ApplicationModel.getInstance();
		}


		public function get viewLocator():ViewLocator
		{
			return ViewLocator.getInstance();
		}
	}
}
